import { getHistorySearchList } from "network/villagesearch";

const moduleHotCity = {
  namespaced: true,
  state: {
    city: localStorage.getItem("city"),//热门城市
    villageSearch: localStorage.getItem("villageSearch"),//记录你当前查询的区域
    historySearchList: [],//搜索记录列表
    currentCity:localStorage.getItem("currentCity"),
  },
  mutations: {
    getCity(state, city) {
      state.city = city
    },
    getvillageSearch(state, villageSearch) {
      state.villageSearch = villageSearch
    },
    addthistorySearch(state, historySearchList) {
      state.historySearchList.push(historySearchList)
    },
    emptyHistorySearchList(state){
      state.historySearchList = []
    },
    getCurrentCity(state,currentCity){
      state.currentCity = currentCity
    }
  },
  actions: {
    uploadHistorySearchList(context,id) {
      context.commit("emptyHistorySearchList")
      getHistorySearchList(id).then(res => {
        console.log(res);
        for(let item of res.data) {
          context.commit("addthistorySearch",item.context)
        }
      })
    }
  }
}

export default moduleHotCity